
<!DOCTYPE HTML>
<html lang="cn" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>简介 · AnyProxy</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        <meta name="author" content="AnyProxy">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        <link rel="shortcut icon" href="/assets/favicon.png" type="image/png">
        <link rel="stylesheet" href="/assets/website.css">
        <script src="/assets/main.js" ></script>
    </head>
    <body>
        <div>
          
        </div>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter active" data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    <div class="summary-title-span 简介">
                      简介
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="./">
            
                <a href="./#快速开始">
            
                    
                    <div class="summary-title-span 快速开始">
                      快速开始
                    </div>

            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="./">
            
                <a href="./#安装">
            
                    
                    <div class="summary-title-span 安装">
                      安装
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="./">
            
                <a href="./#启动">
            
                    
                    <div class="summary-title-span 启动">
                      启动
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="./">
            
                <a href="./#其他命令">
            
                    
                    <div class="summary-title-span 其他命令">
                      其他命令
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="./">
            
                <a href="./#作为npm模块使用">
            
                    
                    <div class="summary-title-span 作为npm模块启动">
                      作为npm模块启动
                    </div>

            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="./">
            
                <a href="./#代理https">
            
                    
                    <div class="summary-title-span 代理HTTPS">
                      代理HTTPS
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="./">
            
                <a href="./#代理websocket">
            
                    
                    <div class="summary-title-span 代理WebSocket">
                      代理WebSocket
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="./">
            
                <a href="./#rule模块">
            
                    
                    <div class="summary-title-span rule模块">
                      rule模块
                    </div>

            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="./">
            
                <a href="./#开发示例">
            
                    
                    <div class="summary-title-span 开发示例">
                      开发示例
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="./">
            
                <a href="./#处理流程">
            
                    
                    <div class="summary-title-span 处理流程">
                      处理流程
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="./">
            
                <a href="./#如何引用">
            
                    
                    <div class="summary-title-span 如何引用">
                      如何引用
                    </div>

            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="./">
            
                <a href="./#rule接口文档">
            
                    
                    <div class="summary-title-span rule接口文档">
                      rule接口文档
                    </div>

            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="./">
            
                <a href="./#summary">
            
                    
                    <div class="summary-title-span rule-title">
                      summary
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="./">
            
                <a href="./#beforesendrequest">
            
                    
                    <div class="summary-title-span rule-title">
                      beforeSendRequest
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="./">
            
                <a href="./#beforesendresponse">
            
                    
                    <div class="summary-title-span rule-title">
                      beforeSendResponse
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="./">
            
                <a href="./#beforedealhttpsrequest">
            
                    
                    <div class="summary-title-span rule-title">
                      beforeDealHttpsRequest
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="./">
            
                <a href="./#onerror">
            
                    
                    <div class="summary-title-span rule-title">
                      onError
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="./">
            
                <a href="./#onconnecterror">
            
                    
                    <div class="summary-title-span rule-title">
                      onConnectError
                    </div>

            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="./">
            
                <a href="./#rule样例">
            
                    
                    <div class="summary-title-span rule样例">
                      rule样例
                    </div>

            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="./">
            
                <a href="./#使用本地数据">
            
                    
                    <div class="summary-title-span sample-title">
                      使用本地数据
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="./">
            
                <a href="./#修改请求头">
            
                    
                    <div class="summary-title-span sample-title">
                      修改请求头
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="./">
            
                <a href="./#修改请求数据">
            
                    
                    <div class="summary-title-span sample-title">
                      修改请求数据
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="./">
            
                <a href="./#修改请求的目标地址">
            
                    
                    <div class="summary-title-span sample-title">
                      修改请求的目标地址
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="./">
            
                <a href="./#修改请求协议">
            
                    
                    <div class="summary-title-span sample-title">
                      修改请求协议
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="./">
            
                <a href="./#修改返回状态码">
            
                    
                    <div class="summary-title-span sample-title">
                      修改返回状态码
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="./">
            
                <a href="./#修改返回头">
            
                    
                    <div class="summary-title-span sample-title">
                      修改返回头
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="./">
            
                <a href="./#修改返回内容并延迟">
            
                    
                    <div class="summary-title-span sample-title">
                      修改返回内容并延迟
                    </div>

            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="./">
            
                <a href="./#证书配置">
            
                    
                    <div class="summary-title-span 证书配置">
                      证书配置
                    </div>

            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="./">
            
                <a href="./#osx系统信任ca证书">
            
                    
                    <div class="summary-title-span OSX系统信任CA证书">
                      OSX系统信任CA证书
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="./">
            
                <a href="./#windows系统信任ca证书">
            
                    
                    <div class="summary-title-span Windows系统信任CA证书">
                      Windows系统信任CA证书
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="./">
            
                <a href="./#配置osx系统代理">
            
                    
                    <div class="summary-title-span 配置OSX系统代理">
                      配置OSX系统代理
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="./">
            
                <a href="./#配置浏览器http代理">
            
                    
                    <div class="summary-title-span 配置浏览器HTTP代理">
                      配置浏览器HTTP代理
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="./">
            
                <a href="./#ios系统信任ca证书">
            
                    
                    <div class="summary-title-span iOS系统信任CA证书">
                      iOS系统信任CA证书
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="./">
            
                <a href="./#ios--103信任ca证书">
            
                    
                    <div class="summary-title-span iOS >= 10.3信任CA证书">
                      iOS >= 10.3信任CA证书
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="./">
            
                <a href="./#安卓系统信任ca证书">
            
                    
                    <div class="summary-title-span 安卓系统信任CA证书">
                      安卓系统信任CA证书
                    </div>

            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="./">
            
                <a href="./#配置iosandroid系统代理">
            
                    
                    <div class="summary-title-span 配置iOS/Android系统代理">
                      配置iOS/Android系统代理
                    </div>

            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="./">
            
                <a href="./#faq">
            
                    
                    <div class="summary-title-span FAQ">
                      FAQ
                    </div>

            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >简介</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="anyproxy">AnyProxy</h1>
<blockquote>
<p>&#x672C;&#x6587;&#x6863;&#x7684;&#x9002;&#x7528;&#x8303;&#x56F4;&#x662F;AnyProxy 4.0&#xFF0C;&#x6B22;&#x8FCE;&#x63D0;&#x4F9B;&#x53CD;&#x9988;</p>
</blockquote>
<p>Ref: <a href="../en">English Doc</a></p>
<p>AnyProxy&#x662F;&#x4E00;&#x4E2A;&#x5F00;&#x653E;&#x5F0F;&#x7684;HTTP&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;&#x3002;</p>
<p>Github&#x4E3B;&#x9875;&#xFF1A;<a href="https://github.com/alibaba/anyproxy" target="_blank">https://github.com/alibaba/anyproxy</a></p>
<p>&#x4E3B;&#x8981;&#x7279;&#x6027;&#x5305;&#x62EC;&#xFF1A;</p>
<ul>
<li>&#x57FA;&#x4E8E;Node.js&#xFF0C;&#x5F00;&#x653E;&#x4E8C;&#x6B21;&#x5F00;&#x53D1;&#x80FD;&#x529B;&#xFF0C;&#x5141;&#x8BB8;&#x81EA;&#x5B9A;&#x4E49;&#x8BF7;&#x6C42;&#x5904;&#x7406;&#x903B;&#x8F91;</li>
<li>&#x652F;&#x6301;Https&#x7684;&#x89E3;&#x6790;</li>
<li>&#x63D0;&#x4F9B;GUI&#x754C;&#x9762;&#xFF0C;&#x7528;&#x4EE5;&#x89C2;&#x5BDF;&#x8BF7;&#x6C42;</li>
</ul>
<p>&#x76F8;&#x6BD4;3.x&#x7248;&#x672C;&#xFF0C;AnyProxy 4.0&#x7684;&#x4E3B;&#x8981;&#x53D8;&#x5316;&#xFF1A;</p>
<ul>
<li>&#x89C4;&#x5219;&#x6587;&#x4EF6;&#xFF08;Rule&#xFF09;&#x5168;&#x9762;&#x652F;&#x6301;Promise&#x548C;Generator</li>
<li>&#x7B80;&#x5316;&#x4E86;&#x89C4;&#x5219;&#x6587;&#x4EF6;&#x5185;&#x7684;&#x63A5;&#x53E3;</li>
<li>Web&#x7248;&#x754C;&#x9762;&#x91CD;&#x6784;</li>
</ul>
<p><img src="https://gw.alipayobjects.com/zos/rmsportal/JoxHUbVhXNedsPUUilnj.gif" width="1275px"></p>
<h1 id="&#x5FEB;&#x901F;&#x5F00;&#x59CB;">&#x5FEB;&#x901F;&#x5F00;&#x59CB;</h1>
<h2 id="&#x4F5C;&#x4E3A;&#x5168;&#x5C40;&#x6A21;&#x5757;">&#x4F5C;&#x4E3A;&#x5168;&#x5C40;&#x6A21;&#x5757;</h2>
<h3 id="&#x5B89;&#x88C5;">&#x5B89;&#x88C5;</h3>
<p>&#x5BF9;&#x4E8E;Debian&#x6216;&#x8005;Ubuntu&#x7CFB;&#x7EDF;&#xFF0C;&#x5728;&#x5B89;&#x88C5;AnyProxy&#x4E4B;&#x524D;&#xFF0C;&#x53EF;&#x80FD;&#x8FD8;&#x9700;&#x8981;&#x5B89;&#x88C5; <code>nodejs-legacy</code></p>
<pre><code class="lang-bash">sudo apt-get install nodejs-legacy
</code></pre>
<p>&#x7136;&#x540E;&#xFF0C;&#x5B89;&#x88C5;AnyProxy</p>
<pre><code class="lang-bash">npm install -g anyproxy
</code></pre>
<h3 id="&#x542F;&#x52A8;">&#x542F;&#x52A8;</h3>
<ul>
<li>&#x547D;&#x4EE4;&#x884C;&#x542F;&#x52A8;AnyProxy&#xFF0C;&#x9ED8;&#x8BA4;&#x7AEF;&#x53E3;&#x53F7;8001</li>
</ul>
<pre><code class="lang-bash">anyproxy
</code></pre>
<ul>
<li>&#x542F;&#x52A8;&#x540E;&#x5C06;&#x7EC8;&#x7AEF;http&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;&#x914D;&#x7F6E;&#x4E3A;127.0.0.1:8001&#x5373;&#x53EF;</li>
<li>&#x8BBF;&#x95EE;<a href="http://127.0.0.1:8002" target="_blank">http://127.0.0.1:8002</a> &#xFF0C;web&#x754C;&#x9762;&#x4E0A;&#x80FD;&#x770B;&#x5230;&#x6240;&#x6709;&#x7684;&#x8BF7;&#x6C42;&#x4FE1;&#x606F;</li>
</ul>
<h3 id="&#x5176;&#x4ED6;&#x547D;&#x4EE4;">&#x5176;&#x4ED6;&#x547D;&#x4EE4;</h3>
<ul>
<li>&#x914D;&#x7F6E;&#x542F;&#x52A8;&#x7AEF;&#x53E3;&#xFF0C;&#x5982;1080&#x7AEF;&#x53E3;&#x542F;&#x52A8;</li>
</ul>
<pre><code class="lang-bash">anyproxy --port 1080
</code></pre>
<h2 id="&#x4F5C;&#x4E3A;npm&#x6A21;&#x5757;&#x4F7F;&#x7528;">&#x4F5C;&#x4E3A;npm&#x6A21;&#x5757;&#x4F7F;&#x7528;</h2>
<p>AnyProxy&#x53EF;&#x4EE5;&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;npm&#x6A21;&#x5757;&#x4F7F;&#x7528;&#xFF0C;&#x6574;&#x5408;&#x8FDB;&#x5176;&#x4ED6;&#x5DE5;&#x5177;&#x3002;</p>
<blockquote>
<p>&#x5982;&#x8981;&#x542F;&#x7528;https&#x89E3;&#x6790;&#xFF0C;&#x8BF7;&#x5728;&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;&#x542F;&#x52A8;&#x524D;&#x81EA;&#x884C;&#x8C03;&#x7528;<code>AnyProxy.utils.certMgr</code>&#x76F8;&#x5173;&#x65B9;&#x6CD5;&#x751F;&#x6210;&#x8BC1;&#x4E66;&#xFF0C;&#x5E76;&#x5F15;&#x5BFC;&#x7528;&#x6237;&#x4FE1;&#x4EFB;&#x5B89;&#x88C5;&#x3002;&#x6216;&#x5F15;&#x5BFC;&#x7528;&#x6237;&#x4F7F;&#x7528;<code>anyproxy-ca</code>&#x65B9;&#x6CD5;&#x3002;</p>
</blockquote>
<ul>
<li>&#x5F15;&#x5165;</li>
</ul>
<pre><code class="lang-bash">npm i anyproxy --save
</code></pre>
<ul>
<li>&#x4F7F;&#x7528;&#x4E3E;&#x4F8B;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> AnyProxy = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;anyproxy&apos;</span>);
<span class="hljs-keyword">const</span> options = {
  port: <span class="hljs-number">8001</span>,
  rule: <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;myRuleModule&apos;</span>),
  webInterface: {
    enable: <span class="hljs-literal">true</span>,
    webPort: <span class="hljs-number">8002</span>
  },
  throttle: <span class="hljs-number">10000</span>,
  forceProxyHttps: <span class="hljs-literal">false</span>,
  wsIntercept: <span class="hljs-literal">false</span>, <span class="hljs-comment">// &#x4E0D;&#x5F00;&#x542F;websocket&#x4EE3;&#x7406;</span>
  silent: <span class="hljs-literal">false</span>
};
<span class="hljs-keyword">const</span> proxyServer = <span class="hljs-keyword">new</span> AnyProxy.ProxyServer(options);

proxyServer.on(<span class="hljs-string">&apos;ready&apos;</span>, () =&gt; { <span class="hljs-comment">/* */</span> });
proxyServer.on(<span class="hljs-string">&apos;error&apos;</span>, (e) =&gt; { <span class="hljs-comment">/* */</span> });
proxyServer.start();

<span class="hljs-comment">//when finished</span>
proxyServer.close();
</code></pre>
<ul>
<li><p>Class: AnyProxy.proxyServer</p>
<ul>
<li><p>&#x521B;&#x5EFA;&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> proxy = <span class="hljs-keyword">new</span> AnyProxy.proxyServer(options)
</code></pre>
</li>
<li><p><code>options</code></p>
<ul>
<li><code>port</code> {number} &#x5FC5;&#x9009;&#xFF0C;&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;&#x7AEF;&#x53E3;</li>
<li><code>rule</code> {object} &#x81EA;&#x5B9A;&#x4E49;&#x89C4;&#x5219;&#x6A21;&#x5757;</li>
<li><code>throttle</code> {number} &#x9650;&#x901F;&#x503C;&#xFF0C;&#x5355;&#x4F4D;kb/s&#xFF0C;&#x9ED8;&#x8BA4;&#x4E0D;&#x9650;&#x901F;</li>
<li><code>forceProxyHttps</code> {boolean} &#x662F;&#x5426;&#x5F3A;&#x5236;&#x62E6;&#x622A;&#x6240;&#x6709;&#x7684;https&#xFF0C;&#x5FFD;&#x7565;&#x89C4;&#x5219;&#x6A21;&#x5757;&#x7684;&#x8FD4;&#x56DE;&#xFF0C;&#x9ED8;&#x8BA4;<code>false</code></li>
<li><code>silent</code> {boolean} &#x662F;&#x5426;&#x5C4F;&#x853D;&#x6240;&#x6709;console&#x8F93;&#x51FA;&#xFF0C;&#x9ED8;&#x8BA4;<code>false</code></li>
<li><code>dangerouslyIgnoreUnauthorized</code> {boolean} &#x662F;&#x5426;&#x5FFD;&#x7565;&#x8BF7;&#x6C42;&#x4E2D;&#x7684;&#x8BC1;&#x4E66;&#x9519;&#x8BEF;&#xFF0C;&#x9ED8;&#x8BA4;<code>false</code></li>
<li><code>wsIntercept</code> {boolean} &#x662F;&#x5426;&#x5F00;&#x542F;websocket&#x4EE3;&#x7406;&#xFF0C;&#x9ED8;&#x8BA4;<code>false</code></li>
<li><code>webInterface</code> {object} web&#x7248;&#x754C;&#x9762;&#x914D;&#x7F6E;<ul>
<li><code>enable</code> {boolean} &#x662F;&#x5426;&#x542F;&#x7528;web&#x7248;&#x754C;&#x9762;&#xFF0C;&#x9ED8;&#x8BA4;<code>false</code></li>
<li><code>webPort</code> {number} web&#x7248;&#x754C;&#x9762;&#x7AEF;&#x53E3;&#x53F7;&#xFF0C;&#x9ED8;&#x8BA4;<code>8002</code></li>
</ul>
</li>
</ul>
</li>
<li><p>Event: <code>ready</code></p>
<ul>
<li>&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;&#x542F;&#x52A8;&#x5B8C;&#x6210;</li>
<li>&#x793A;&#x4F8B;</li>
</ul>
<pre><code class="lang-js">proxy.on(<span class="hljs-string">&apos;ready&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{ })
</code></pre>
</li>
<li><p>Event: <code>error</code></p>
<ul>
<li>&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;&#x53D1;&#x751F;&#x9519;&#x8BEF;</li>
<li>&#x793A;&#x4F8B;</li>
</ul>
<pre><code class="lang-js">proxy.on(<span class="hljs-string">&apos;error&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{ })
</code></pre>
</li>
<li><p>Method: <code>start</code></p>
<ul>
<li>&#x542F;&#x52A8;&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;</li>
<li>&#x793A;&#x4F8B;</li>
</ul>
<pre><code class="lang-js">proxy.start();
</code></pre>
</li>
<li><p>Method: <code>close</code></p>
<ul>
<li>&#x5173;&#x95ED;&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;</li>
<li>&#x793A;&#x4F8B;</li>
</ul>
<pre><code class="lang-js">proxy.close();
</code></pre>
</li>
</ul>
</li>
<li><p>AnyProxy.utils.systemProxyMgr</p>
<ul>
<li>&#x7BA1;&#x7406;&#x7CFB;&#x7EDF;&#x7684;&#x5168;&#x5C40;&#x4EE3;&#x7406;&#x914D;&#x7F6E;&#xFF0C;&#x65B9;&#x6CD5;&#x8C03;&#x7528;&#x65F6;&#x53EF;&#x80FD;&#x4F1A;&#x5F39;&#x51FA;&#x5BC6;&#x7801;&#x6846;</li>
<li>&#x4F7F;&#x7528;&#x793A;&#x4F8B;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// &#x914D;&#x7F6E;127.0.0.1:8001&#x4E3A;&#x5168;&#x5C40;http&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;</span>
AnyProxy.utils.systemProxyMgr.enableGlobalProxy(<span class="hljs-string">&apos;127.0.0.1&apos;</span>, <span class="hljs-string">&apos;8001&apos;</span>);

<span class="hljs-comment">// &#x5173;&#x95ED;&#x5168;&#x5C40;&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;</span>
AnyProxy.utils.systemProxyMgr.disableGlobalProxy();
</code></pre>
</li>
<li><p>AnyProxy.utils.certMgr</p>
<ul>
<li>&#x7BA1;&#x7406;AnyProxy&#x7684;&#x8BC1;&#x4E66;</li>
<li><code>AnyProxy.utils.certMgr.ifRootCAFileExists()</code><ul>
<li>&#x6821;&#x9A8C;&#x7CFB;&#x7EDF;&#x5185;&#x662F;&#x5426;&#x5B58;&#x5728;AnyProxy&#x7684;&#x6839;&#x8BC1;&#x4E66;</li>
</ul>
</li>
<li><code>AnyProxy.utils.certMgr.generateRootCA(callback)</code><ul>
<li>&#x751F;&#x6210;AnyProxy&#x7684;rootCA&#xFF0C;&#x5B8C;&#x6210;&#x540E;&#x8BF7;&#x5F15;&#x5BFC;&#x7528;&#x6237;&#x4FE1;&#x4EFB;.crt&#x6587;&#x4EF6;</li>
</ul>
</li>
<li>&#x6837;&#x4F8B;</li>
</ul>
<pre><code class="lang-js">  <span class="hljs-keyword">const</span> AnyProxy = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;anyproxy&apos;</span>);
  <span class="hljs-keyword">const</span> exec = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;child_process&apos;</span>).exec;

  <span class="hljs-keyword">if</span> (!AnyProxy.utils.certMgr.ifRootCAFileExists()) {
    AnyProxy.utils.certMgr.generateRootCA((error, keyPath) =&gt; {
      <span class="hljs-comment">// let users to trust this CA before using proxy</span>
      <span class="hljs-keyword">if</span> (!error) {
        <span class="hljs-keyword">const</span> certDir = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>).dirname(keyPath);
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;The cert is generated at&apos;</span>, certDir);
        <span class="hljs-keyword">const</span> isWin = <span class="hljs-regexp">/^win/</span>.test(process.platform);
        <span class="hljs-keyword">if</span> (isWin) {
          exec(<span class="hljs-string">&apos;start .&apos;</span>, { cwd: certDir });
        } <span class="hljs-keyword">else</span> {
          exec(<span class="hljs-string">&apos;open .&apos;</span>, { cwd: certDir });
        }
      } <span class="hljs-keyword">else</span> {
        <span class="hljs-built_in">console</span>.error(<span class="hljs-string">&apos;error when generating rootCA&apos;</span>, error);
      }
    });
  }
</code></pre>
</li>
</ul>
<h1 id="&#x4EE3;&#x7406;https">&#x4EE3;&#x7406;HTTPS</h1>
<ul>
<li>AnyProxy&#x9ED8;&#x8BA4;&#x4E0D;&#x5BF9;https&#x8BF7;&#x6C42;&#x505A;&#x5904;&#x7406;&#xFF0C;&#x5982;&#x9700;&#x770B;&#x5230;&#x660E;&#x6587;&#x4FE1;&#x606F;&#xFF0C;&#x9700;&#x8981;&#x914D;&#x7F6E;CA&#x8BC1;&#x4E66;</li>
</ul>
<blockquote>
<p>&#x89E3;&#x6790;https&#x8BF7;&#x6C42;&#x7684;&#x539F;&#x7406;&#x662F;&#x4E2D;&#x95F4;&#x4EBA;&#x653B;&#x51FB;&#xFF08;man-in-the-middle&#xFF09;&#xFF0C;&#x7528;&#x6237;&#x5FC5;&#x987B;&#x4FE1;&#x4EFB;AnyProxy&#x751F;&#x6210;&#x7684;CA&#x8BC1;&#x4E66;&#xFF0C;&#x624D;&#x80FD;&#x8FDB;&#x884C;&#x540E;&#x7EED;&#x6D41;&#x7A0B;</p>
</blockquote>
<ul>
<li>&#x751F;&#x6210;&#x8BC1;&#x4E66;&#x5E76;&#x89E3;&#x6790;&#x6240;&#x6709;https&#x8BF7;&#x6C42;</li>
</ul>
<pre><code class="lang-bash">anyproxy-ca <span class="hljs-comment">#&#x751F;&#x6210;rootCA&#x8BC1;&#x4E66;&#xFF0C;&#x751F;&#x6210;&#x540E;&#x9700;&#x8981;&#x624B;&#x52A8;&#x4FE1;&#x4EFB;</span>
anyproxy --intercept <span class="hljs-comment">#&#x542F;&#x52A8;AnyProxy&#xFF0C;&#x5E76;&#x89E3;&#x6790;&#x6240;&#x6709;https&#x8BF7;&#x6C42;</span>
</code></pre>
<ul>
<li><a href="#&#x8BC1;&#x4E66;&#x914D;&#x7F6E;">&#x9644;&#x5F55;&#xFF1A;&#x5982;&#x4F55;&#x4FE1;&#x4EFB;CA&#x8BC1;&#x4E66;</a></li>
</ul>
<h1 id="&#x4EE3;&#x7406;websocket">&#x4EE3;&#x7406;WebSocket</h1>
<pre><code class="lang-bash">anyproxy --ws-intercept
</code></pre>
<blockquote>
<p>&#x5F53;&#x542F;&#x7528;<code>HTTPS</code>&#x4EE3;&#x7406;&#x65F6;&#xFF0C;<code>wss</code>&#x4E5F;&#x4F1A;&#x88AB;&#x4EE3;&#x7406;&#xFF0C;&#x4F46;&#x662F;&#x4E0D;&#x4F1A;&#x88AB;AnyProxy&#x8BB0;&#x5F55;&#x3002;&#x9700;&#x8981;&#x5F00;&#x542F;<code>--ws-intercept</code>&#x540E;&#x624D;&#x4F1A;&#x4ECE;&#x754C;&#x9762;&#x4E0A;&#x770B;&#x5230;&#x76F8;&#x5E94;&#x5185;&#x5BB9;&#x3002;</p>
</blockquote>
<h1 id="rule&#x6A21;&#x5757;">rule&#x6A21;&#x5757;</h1>
<p>AnyProxy&#x63D0;&#x4F9B;&#x4E86;&#x4E8C;&#x6B21;&#x5F00;&#x53D1;&#x7684;&#x80FD;&#x529B;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x7528;js&#x7F16;&#x5199;&#x81EA;&#x5DF1;&#x7684;&#x89C4;&#x5219;&#x6A21;&#x5757;&#xFF08;rule&#xFF09;&#xFF0C;&#x6765;&#x81EA;&#x5B9A;&#x4E49;&#x7F51;&#x7EDC;&#x8BF7;&#x6C42;&#x7684;&#x5904;&#x7406;&#x903B;&#x8F91;&#x3002;</p>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x5F15;&#x7528;&#x89C4;&#x5219;&#x524D;&#xFF0C;&#x8BF7;&#x52A1;&#x5FC5;&#x786E;&#x4FDD;&#x6587;&#x4EF6;&#x6765;&#x6E90;&#x53EF;&#x9760;&#xFF0C;&#x4EE5;&#x514D;&#x53D1;&#x751F;&#x5B89;&#x5168;&#x95EE;&#x9898;</p>
</blockquote>
<p>&#x89C4;&#x5219;&#x6A21;&#x5757;&#x7684;&#x80FD;&#x529B;&#x8303;&#x56F4;&#x5305;&#x62EC;&#xFF1A;</p>
<ul>
<li>&#x62E6;&#x622A;&#x5E76;&#x4FEE;&#x6539;&#x6B63;&#x5728;&#x53D1;&#x9001;&#x7684;&#x8BF7;&#x6C42;<ul>
<li>&#x53EF;&#x4FEE;&#x6539;&#x5185;&#x5BB9;&#x5305;&#x62EC;&#x8BF7;&#x6C42;&#x5934;&#xFF08;request header)&#xFF0C;&#x8BF7;&#x6C42;&#x4F53;&#xFF08;request body&#xFF09;&#xFF0C;&#x751A;&#x81F3;&#x662F;&#x8BF7;&#x6C42;&#x7684;&#x76EE;&#x6807;&#x5730;&#x5740;&#x7B49;</li>
</ul>
</li>
<li>&#x62E6;&#x622A;&#x5E76;&#x4FEE;&#x6539;&#x670D;&#x52A1;&#x7AEF;&#x54CD;&#x5E94;<ul>
<li>&#x53EF;&#x4FEE;&#x6539;&#x7684;&#x5185;&#x5BB9;&#x5305;&#x62EC;http&#x72B6;&#x6001;&#x7801;(status code)&#x3001;&#x54CD;&#x5E94;&#x5934;&#xFF08;response header&#xFF09;&#x3001;&#x54CD;&#x5E94;&#x5185;&#x5BB9;&#x7B49;</li>
</ul>
</li>
<li>&#x62E6;&#x622A;https&#x8BF7;&#x6C42;&#xFF0C;&#x5BF9;&#x5185;&#x5BB9;&#x505A;&#x4FEE;&#x6539;<ul>
<li>&#x672C;&#x8D28;&#x662F;&#x4E2D;&#x95F4;&#x4EBA;&#x653B;&#x51FB;&#xFF08;man-in-the-middle attack&#xFF09;&#xFF0C;&#x9700;&#x8981;&#x5BA2;&#x6237;&#x7AEF;&#x63D0;&#x524D;&#x4FE1;&#x4EFB;AnyProxy&#x751F;&#x6210;&#x7684;CA</li>
</ul>
</li>
</ul>
<h3 id="&#x5F00;&#x53D1;&#x793A;&#x4F8B;">&#x5F00;&#x53D1;&#x793A;&#x4F8B;</h3>
<ul>
<li><p>&#x4E3E;&#x4F8B;</p>
<ul>
<li>&#x9700;&#x8981;&#x7F16;&#x5199;&#x4E00;&#x4E2A;&#x89C4;&#x5219;&#x6A21;&#x5757;&#xFF0C;&#x5728; GET <a href="http://httpbin.org/user-agent" target="_blank">http://httpbin.org/user-agent</a> &#x7684;&#x8FD4;&#x56DE;&#x503C;&#x91CC;&#x52A0;&#x4E0A;&#x6D4B;&#x8BD5;&#x4FE1;&#x606F;&#xFF0C;&#x5E76;&#x5EF6;&#x8FDF;5&#x79D2;&#x8FD4;&#x56DE;</li>
</ul>
</li>
<li><p>Step 1&#xFF0C;&#x7F16;&#x5199;&#x89C4;&#x5219;</p>
<pre><code class="lang-js"><span class="hljs-comment">// file: sample.js</span>
<span class="hljs-built_in">module</span>.exports = {
  summary: <span class="hljs-string">&apos;a rule to hack response&apos;</span>,
  *beforeSendResponse(requestDetail, responseDetail) {
    <span class="hljs-keyword">if</span> (requestDetail.url === <span class="hljs-string">&apos;http://httpbin.org/user-agent&apos;</span>) {
      <span class="hljs-keyword">const</span> newResponse = responseDetail.response;
      newResponse.body += <span class="hljs-string">&apos;- AnyProxy Hacked!&apos;</span>;

      <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>((resolve, reject) =&gt; {
        setTimeout(() =&gt; { <span class="hljs-comment">// delay</span>
          resolve({ response: newResponse });
        }, <span class="hljs-number">5000</span>);
      });
    }
  },
};
</code></pre>
</li>
<li><p>Step 2, &#x542F;&#x52A8;AnyProxy&#xFF0C;&#x52A0;&#x8F7D;&#x89C4;&#x5219;</p>
<ul>
<li>&#x8FD0;&#x884C; <code>anyproxy --rule sample.js</code></li>
</ul>
</li>
<li><p>Step 3, &#x6D4B;&#x8BD5;&#x89C4;&#x5219;</p>
<ul>
<li><p>&#x7528;curl&#x6D4B;&#x8BD5;</p>
<pre><code class="lang-bash">curl http://httpbin.org/user-agent --proxy http://127.0.0.1:8001
</code></pre>
</li>
<li><p>&#x7528;&#x6D4F;&#x89C8;&#x5668;&#x6D4B;&#x8BD5;&#xFF1A;&#x914D;&#x7F6E;&#x6D4F;&#x89C8;&#x5668;http&#x4EE3;&#x7406;&#x4E3A; 127.0.0.1:8001&#xFF0C;&#x8BBF;&#x95EE; <a href="http://httpbin.org/user-agent" target="_blank">http://httpbin.org/user-agent</a></p>
</li>
<li><p>&#x7ECF;&#x8FC7;&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;&#x540E;&#xFF0C;&#x671F;&#x671B;&#x7684;&#x8FD4;&#x56DE;&#x5982;&#x4E0B;</p>
</li>
</ul>
<pre><code>{
  &quot;user-agent&quot;: &quot;curl/7.43.0&quot;
}
- AnyProxy Hacked!
</code></pre></li>
<li><p>Step 4, &#x67E5;&#x770B;&#x8BF7;&#x6C42;&#x4FE1;&#x606F;</p>
<ul>
<li>&#x6D4F;&#x89C8;&#x5668;&#x8BBF;&#x95EE;<a href="http://127.0.0.1:8002" target="_blank">http://127.0.0.1:8002</a> &#xFF0C;&#x754C;&#x9762;&#x4E0A;&#x80FD;&#x770B;&#x5230;&#x521A;&#x624D;&#x7684;&#x8BF7;&#x6C42;&#x4FE1;&#x606F;</li>
</ul>
</li>
</ul>
<h3 id="&#x5904;&#x7406;&#x6D41;&#x7A0B;">&#x5904;&#x7406;&#x6D41;&#x7A0B;</h3>
<ul>
<li>&#x5904;&#x7406;&#x6D41;&#x7A0B;&#x56FE;&#x5982;&#x4E0B;</li>
</ul>
<p><img src="https://zos.alipayobjects.com/rmsportal/TWyNuSJtEZBdrdcOMRjE.png" width="550"></p>
<ul>
<li><p>&#x5F53;http&#x8BF7;&#x6C42;&#x7ECF;&#x8FC7;&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;&#x65F6;&#xFF0C;&#x5177;&#x4F53;&#x5904;&#x7406;&#x8FC7;&#x7A0B;&#x662F;&#xFF1A;</p>
<ul>
<li>&#x6536;&#x96C6;&#x8BF7;&#x6C42;&#x6240;&#x6709;&#x8BF7;&#x6C42;&#x53C2;&#x6570;&#xFF0C;&#x5305;&#x62EC;method, header, body&#x7B49;</li>
<li>AnyProxy&#x8C03;&#x7528;&#x89C4;&#x5219;&#x6A21;&#x5757;<code>beforeSendRequest</code>&#x65B9;&#x6CD5;&#xFF0C;&#x7531;&#x6A21;&#x5757;&#x505A;&#x5904;&#x7406;&#xFF0C;&#x8FD4;&#x56DE;&#x65B0;&#x7684;&#x8BF7;&#x6C42;&#x53C2;&#x6570;&#xFF0C;&#x6216;&#x8FD4;&#x56DE;&#x54CD;&#x5E94;&#x5185;&#x5BB9;</li>
<li>&#x5982;&#x679C;<code>beforeSendRequest</code>&#x8FD4;&#x56DE;&#x4E86;&#x54CD;&#x5E94;&#x5185;&#x5BB9;&#xFF0C;&#x5219;&#x7ACB;&#x5373;&#x628A;&#x6B64;&#x54CD;&#x5E94;&#x8FD4;&#x56DE;&#x5230;&#x5BA2;&#x6237;&#x7AEF;&#xFF08;&#x800C;&#x4E0D;&#x518D;&#x53D1;&#x9001;&#x5230;&#x771F;&#x6B63;&#x7684;&#x670D;&#x52A1;&#x7AEF;&#xFF09;&#xFF0C;&#x6D41;&#x7A0B;&#x7ED3;&#x675F;&#x3002;</li>
<li>&#x6839;&#x636E;&#x8BF7;&#x6C42;&#x53C2;&#x6570;&#xFF0C;&#x5411;&#x670D;&#x52A1;&#x7AEF;&#x53D1;&#x51FA;&#x8BF7;&#x6C42;&#xFF0C;&#x63A5;&#x6536;&#x670D;&#x52A1;&#x7AEF;&#x54CD;&#x5E94;&#x3002;</li>
<li>&#x8C03;&#x7528;&#x89C4;&#x5219;&#x6A21;&#x5757;<code>beforeSendResponse</code>&#x65B9;&#x6CD5;&#xFF0C;&#x7531;&#x6A21;&#x5757;&#x5BF9;&#x54CD;&#x5E94;&#x5185;&#x5BB9;&#x8FDB;&#x884C;&#x5904;&#x7406;</li>
<li>&#x628A;&#x54CD;&#x5E94;&#x4FE1;&#x606F;&#x8FD4;&#x56DE;&#x7ED9;&#x5BA2;&#x6237;&#x7AEF;</li>
</ul>
</li>
<li><p>&#x5F53;&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;&#x6536;&#x5230;https&#x8BF7;&#x6C42;&#x65F6;&#xFF0C;AnyProxy&#x53EF;&#x4EE5;&#x66FF;&#x6362;&#x8BC1;&#x4E66;&#xFF0C;&#x5BF9;&#x8BF7;&#x6C42;&#x505A;&#x660E;&#x6587;&#x89E3;&#x6790;&#x3002;</p>
<ul>
<li>&#x8C03;&#x7528;&#x89C4;&#x5219;&#x6A21;&#x5757;<code>beforeDealHttpsRequest</code>&#x65B9;&#x6CD5;&#xFF0C;&#x5982;&#x679C;&#x8FD4;&#x56DE;<code>true</code>&#xFF0C;&#x4F1A;&#x660E;&#x6587;&#x89E3;&#x6790;&#x8FD9;&#x4E2A;&#x8BF7;&#x6C42;&#xFF0C;&#x5176;&#x4ED6;&#x8BF7;&#x6C42;&#x4E0D;&#x5904;&#x7406;</li>
<li>&#x88AB;&#x660E;&#x6587;&#x89E3;&#x6790;&#x540E;&#x7684;https&#x8BF7;&#x6C42;&#xFF0C;&#x5904;&#x7406;&#x6D41;&#x7A0B;&#x540C;http&#x4E00;&#x81F4;&#x3002;&#x672A;&#x660E;&#x6587;&#x89E3;&#x6790;&#x8BF7;&#x6C42;&#x4E0D;&#x4F1A;&#x518D;&#x8FDB;&#x5165;&#x89C4;&#x5219;&#x6A21;&#x5757;&#x505A;&#x5904;&#x7406;&#x3002;</li>
</ul>
</li>
</ul>
<h3 id="&#x5982;&#x4F55;&#x5F15;&#x7528;">&#x5982;&#x4F55;&#x5F15;&#x7528;</h3>
<p>&#x5982;&#x4E0B;&#x51E0;&#x79CD;&#x65B9;&#x6848;&#x90FD;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x5F15;&#x7528;&#x89C4;&#x5219;&#x6A21;&#x5757;&#xFF1A;</p>
<ul>
<li>&#x4F7F;&#x7528;&#x672C;&#x5730;&#x8DEF;&#x5F84;<pre><code class="lang-bash">anyproxy --rule ./rule.js
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528;&#x5728;&#x7EBF;&#x5730;&#x5740;</p>
<pre><code class="lang-bash">anyproxy --rule https://sample.com/rule.js
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528;npm&#x5305;</p>
<ul>
<li>AnyProxy&#x4F7F;&#x7528;<code>require()</code>&#x52A0;&#x8F7D;&#x672C;&#x5730;&#x89C4;&#x5219;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x5728;&#x53C2;&#x6570;&#x91CC;&#x4F20;&#x5165;&#x4E00;&#x4E2A;&#x672C;&#x5730;&#x7684;npm&#x5305;&#x8DEF;&#x5F84;&#xFF0C;&#x6216;&#x662F;&#x67D0;&#x4E2A;&#x5168;&#x5C40;&#x5B89;&#x88C5;&#x7684;npm&#x5305;</li>
</ul>
<pre><code class="lang-bash">anyproxy --rule ./myRulePkg/ <span class="hljs-comment">#&#x672C;&#x5730;&#x5305;</span>
npm i -g myRulePkg &amp;&amp; anyproxy --rule myRulePkg <span class="hljs-comment">#&#x5168;&#x5C40;&#x5305;</span>
</code></pre>
</li>
</ul>
<h1 id="rule&#x63A5;&#x53E3;&#x6587;&#x6863;">rule&#x63A5;&#x53E3;&#x6587;&#x6863;</h1>
<p>&#x89C4;&#x5219;&#x6A21;&#x5757;&#x5E94;&#x8BE5;&#x7B26;&#x5408;cmd&#x89C4;&#x8303;&#xFF0C;&#x4E00;&#x4E2A;&#x5178;&#x578B;&#x7684;&#x89C4;&#x5219;&#x6A21;&#x5757;&#x4EE3;&#x7801;&#x7ED3;&#x6784;&#x5982;&#x4E0B;&#x3002;&#x6A21;&#x5757;&#x4E2D;&#x6240;&#x6709;&#x65B9;&#x6CD5;&#x90FD;&#x662F;&#x53EF;&#x9009;&#x7684;&#xFF0C;&#x53EA;&#x9700;&#x5B9E;&#x73B0;&#x4E1A;&#x52A1;&#x611F;&#x5174;&#x8DA3;&#x7684;&#x90E8;&#x5206;&#x5373;&#x53EF;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-comment">// &#x6A21;&#x5757;&#x4ECB;&#x7ECD;</span>
  summary: <span class="hljs-string">&apos;my customized rule for AnyProxy&apos;</span>,
  <span class="hljs-comment">// &#x53D1;&#x9001;&#x8BF7;&#x6C42;&#x524D;&#x62E6;&#x622A;&#x5904;&#x7406;</span>
  *beforeSendRequest(requestDetail) { <span class="hljs-comment">/* ... */</span> },
  <span class="hljs-comment">// &#x53D1;&#x9001;&#x54CD;&#x5E94;&#x524D;&#x5904;&#x7406;</span>
  *beforeSendResponse(requestDetail, responseDetail) { <span class="hljs-comment">/* ... */</span> },
  <span class="hljs-comment">// &#x662F;&#x5426;&#x5904;&#x7406;https&#x8BF7;&#x6C42;</span>
  *beforeDealHttpsRequest(requestDetail) { <span class="hljs-comment">/* ... */</span> },
  <span class="hljs-comment">// &#x8BF7;&#x6C42;&#x51FA;&#x9519;&#x7684;&#x4E8B;&#x4EF6;</span>
  *onError(requestDetail, error) { <span class="hljs-comment">/* ... */</span> },
  <span class="hljs-comment">// https&#x8FDE;&#x63A5;&#x670D;&#x52A1;&#x5668;&#x51FA;&#x9519;</span>
  *onConnectError(requestDetail, error) { <span class="hljs-comment">/* ... */</span> }
};
</code></pre>
<blockquote>
<p>&#x89C4;&#x5219;&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x9664;&#x4E86;summary&#xFF0C;&#x90FD;&#x662F;&#x7531; <a href="https://www.npmjs.com/package/co" target="_blank">co</a> &#x9A71;&#x52A8;&#x7684;&#xFF0C;&#x51FD;&#x6570;&#x9700;&#x8981;&#x6EE1;&#x8DB3;yieldable&#x3002;&#x53EF;&#x4EE5;&#x8FD4;&#x56DE;promise&#x6216;&#x4F7F;&#x7528;generator&#x51FD;&#x6570;&#x3002;</p>
</blockquote>
<h3 id="summary">summary</h3>
<h4 id="summary-string--summarystring">summary(): string | summary:string</h4>
<ul>
<li>&#x89C4;&#x5219;&#x6A21;&#x5757;&#x7684;&#x4ECB;&#x7ECD;&#x6587;&#x6848;&#xFF0C;&#x7528;&#x4E8E;AnyProxy&#x63D0;&#x793A;&#x7528;&#x6237;, &#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x666E;&#x901A;&#x7684;&#x5B57;&#x7B26;&#x4E32;</li>
</ul>
<h3 id="beforesendrequest">beforeSendRequest</h3>
<h4 id="beforesendrequestrequestdetail">beforeSendRequest(requestDetail)</h4>
<ul>
<li>AnyProxy&#x5411;&#x670D;&#x52A1;&#x7AEF;&#x53D1;&#x9001;&#x8BF7;&#x6C42;&#x524D;&#xFF0C;&#x4F1A;&#x8C03;&#x7528;<code>beforeSendRequest</code>&#xFF0C;&#x5E76;&#x5E26;&#x4E0A;&#x53C2;&#x6570;<code>requestDetail</code></li>
<li><code>requestDetail</code><ul>
<li><code>protocol</code> {string} &#x8BF7;&#x6C42;&#x4F7F;&#x7528;&#x7684;&#x534F;&#x8BAE;&#xFF0C;http&#x6216;&#x8005;https</li>
<li><code>requestOptions</code> {object} &#x5373;&#x5C06;&#x53D1;&#x9001;&#x7684;&#x8BF7;&#x6C42;&#x914D;&#x7F6E;&#xFF0C;&#x4F9B;require(&apos;http&apos;).request&#x4F5C;&#x4E3A;&#x4F7F;&#x7528;&#x3002;&#x8BE6;&#x89C1;&#xFF1A;<a href="https://nodejs.org/api/http.html#http_http_request_options_callback" target="_blank">https://nodejs.org/api/http.html#http_http_request_options_callback</a></li>
<li><code>requestData</code> {object} &#x8BF7;&#x6C42;Body</li>
<li><code>url</code> {string} &#x8BF7;&#x6C42;url</li>
<li><code>_req</code> {object} &#x8BF7;&#x6C42;&#x7684;&#x539F;&#x59CB;request</li>
</ul>
</li>
<li><p>&#x4E3E;&#x4F8B;&#xFF1A;&#x8BF7;&#x6C42; <em>anyproxy.io</em> &#x65F6;&#xFF0C;<code>requestDetail</code>&#x53C2;&#x6570;&#x5185;&#x5BB9;&#x5927;&#x81F4;&#x5982;&#x4E0B;</p>
<pre><code class="lang-js">{
  protocol: <span class="hljs-string">&apos;http&apos;</span>,
  url: <span class="hljs-string">&apos;http://anyproxy.io/&apos;</span>,
  requestOptions: {
    hostname: <span class="hljs-string">&apos;anyproxy.io&apos;</span>,
    port: <span class="hljs-number">80</span>,
    path: <span class="hljs-string">&apos;/&apos;</span>,
    method: <span class="hljs-string">&apos;GET&apos;</span>,
    headers: {
      Host: <span class="hljs-string">&apos;anyproxy.io&apos;</span>,
      <span class="hljs-string">&apos;Proxy-Connection&apos;</span>: <span class="hljs-string">&apos;keep-alive&apos;</span>,
      <span class="hljs-string">&apos;User-Agent&apos;</span>: <span class="hljs-string">&apos;...&apos;</span>
    }
  },
  requestData: <span class="hljs-string">&apos;...&apos;</span>,
  _req: { <span class="hljs-comment">/* ... */</span>}
}
</code></pre>
</li>
<li><p>&#x4EE5;&#x4E0B;&#x51E0;&#x79CD;&#x8FD4;&#x56DE;&#x90FD;&#x662F;&#x5408;&#x6CD5;&#x7684;</p>
<ul>
<li>&#x4E0D;&#x505A;&#x4EFB;&#x4F55;&#x5904;&#x7406;&#xFF0C;&#x8FD4;&#x56DE;null</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;
</code></pre>
<ul>
<li>&#x4FEE;&#x6539;&#x8BF7;&#x6C42;&#x534F;&#x8BAE;&#xFF0C;&#x5982;&#x5F3A;&#x5236;&#x6539;&#x7528;https&#x53D1;&#x8D77;&#x8BF7;&#x6C42;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">return</span> {
  protocol: <span class="hljs-string">&apos;https&apos;</span>
};
</code></pre>
<ul>
<li>&#x4FEE;&#x6539;&#x8BF7;&#x6C42;&#x53C2;&#x6570;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> newOption = <span class="hljs-built_in">Object</span>.assign({}, requestDetail.requestOptions);
newOption.path = <span class="hljs-string">&apos;/redirect/to/another/path&apos;</span>;
<span class="hljs-keyword">return</span> {
  requestOptions: newOption
};
</code></pre>
<ul>
<li>&#x4FEE;&#x6539;&#x8BF7;&#x6C42;body</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">return</span> {
  requestData: <span class="hljs-string">&apos;my new request data&apos;</span>
  <span class="hljs-comment">//&#x8FD9;&#x91CC;&#x4E5F;&#x53EF;&#x4EE5;&#x540C;&#x65F6;&#x52A0;&#x4E0A;requestOptions</span>
};
</code></pre>
<ul>
<li>&#x76F4;&#x63A5;&#x8FD4;&#x56DE;&#x5BA2;&#x6237;&#x7AEF;&#xFF0C;&#x4E0D;&#x518D;&#x53D1;&#x8D77;&#x8BF7;&#x6C42;&#xFF0C;&#x5176;&#x4E2D;<code>statusCode</code> <code>header</code> &#x662F;&#x5FC5;&#x9009;&#x5B57;&#x6BB5;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">return</span> {
  response: {
    statusCode: <span class="hljs-number">200</span>,
    header: { <span class="hljs-string">&apos;content-type&apos;</span>: <span class="hljs-string">&apos;text/html&apos;</span> },
    body: <span class="hljs-string">&apos;this could be a &lt;string&gt; or &lt;buffer&gt;&apos;</span>
  }
};
</code></pre>
</li>
</ul>
<h3 id="beforesendresponse">beforeSendResponse</h3>
<h4 id="beforesendresponserequestdetail-responsedetail">beforeSendResponse(requestDetail, responseDetail)</h4>
<ul>
<li>AnyProxy&#x5411;&#x5BA2;&#x6237;&#x7AEF;&#x53D1;&#x9001;&#x8BF7;&#x6C42;&#x524D;&#xFF0C;&#x4F1A;&#x8C03;&#x7528;<code>beforeSendResponse</code>&#xFF0C;&#x5E76;&#x5E26;&#x4E0A;&#x53C2;&#x6570;<code>requestDetail</code> <code>responseDetail</code></li>
<li><code>requestDetail</code> &#x540C;<code>beforeSendRequest</code>&#x4E2D;&#x7684;&#x53C2;&#x6570;</li>
<li><code>responseDetail</code><ul>
<li><code>response</code> {object} &#x670D;&#x52A1;&#x7AEF;&#x7684;&#x8FD4;&#x56DE;&#x4FE1;&#x606F;&#xFF0C;&#x5305;&#x62EC;<code>statusCode</code> <code>header</code> <code>body</code>&#x4E09;&#x4E2A;&#x5B57;&#x6BB5;</li>
<li><code>_res</code> {object} &#x539F;&#x59CB;&#x7684;&#x670D;&#x52A1;&#x7AEF;&#x8FD4;&#x56DE;&#x5BF9;&#x8C61;</li>
</ul>
</li>
<li><p>&#x4E3E;&#x4F8B;&#xFF0C;&#x8BF7;&#x6C42; <em>anyproxy.io</em> &#x65F6;&#xFF0C;<code>responseDetail</code>&#x53C2;&#x6570;&#x5185;&#x5BB9;&#x5927;&#x81F4;&#x5982;&#x4E0B;</p>
<pre><code class="lang-js">{
  response: {
    statusCode: <span class="hljs-number">200</span>,
    header: {
      <span class="hljs-string">&apos;Content-Type&apos;</span>: <span class="hljs-string">&apos;image/gif&apos;</span>,
      Connection: <span class="hljs-string">&apos;close&apos;</span>,
      <span class="hljs-string">&apos;Cache-Control&apos;</span>: <span class="hljs-string">&apos;...&apos;</span>
    },
    body: <span class="hljs-string">&apos;...&apos;</span>
  },
  _res: { <span class="hljs-comment">/* ... */</span> }
}
</code></pre>
</li>
<li><p>&#x4EE5;&#x4E0B;&#x51E0;&#x79CD;&#x8FD4;&#x56DE;&#x90FD;&#x662F;&#x5408;&#x6CD5;&#x7684;</p>
<ul>
<li>&#x4E0D;&#x505A;&#x4EFB;&#x4F55;&#x5904;&#x7406;&#xFF0C;&#x8FD4;&#x56DE;null</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;
</code></pre>
<ul>
<li>&#x4FEE;&#x6539;&#x8FD4;&#x56DE;&#x7684;&#x72B6;&#x6001;&#x7801;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> newResponse = <span class="hljs-built_in">Object</span>.assign({}, responseDetail.response);
newResponse.statusCode = <span class="hljs-number">404</span>;
<span class="hljs-keyword">return</span> {
  response: newResponse
};
</code></pre>
<ul>
<li>&#x4FEE;&#x6539;&#x8FD4;&#x56DE;&#x7684;&#x5185;&#x5BB9;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> newResponse = <span class="hljs-built_in">Object</span>.assign({}, responseDetail.response);
newResponse.body += <span class="hljs-string">&apos;--from anyproxy--&apos;</span>;
<span class="hljs-keyword">return</span> {
  response: newResponse
};
</code></pre>
</li>
</ul>
<h3 id="beforedealhttpsrequest">beforeDealHttpsRequest</h3>
<h4 id="beforedealhttpsrequestrequestdetail">beforeDealHttpsRequest(requestDetail)</h4>
<ul>
<li>AnyProxy&#x6536;&#x5230;https&#x8BF7;&#x6C42;&#x65F6;&#xFF0C;&#x4F1A;&#x8C03;&#x7528;<code>beforeDealHttpsRequest</code>&#xFF0C;&#x5E76;&#x5E26;&#x4E0A;&#x53C2;&#x6570;<code>requestDetail</code></li>
<li>&#x5982;&#x679C;&#x914D;&#x7F6E;&#x4E86;&#x5168;&#x5C40;&#x89E3;&#x6790;https&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x5219;AnyProxy&#x4F1A;&#x7565;&#x8FC7;&#x8FD9;&#x4E2A;&#x8C03;&#x7528;</li>
<li>&#x53EA;&#x6709;&#x8FD4;&#x56DE;<code>true</code>&#x65F6;&#xFF0C;AnyProxy&#x624D;&#x4F1A;&#x5C1D;&#x8BD5;&#x66FF;&#x6362;&#x8BC1;&#x4E66;&#x3001;&#x89E3;&#x6790;https&#x3002;&#x5426;&#x5219;&#x53EA;&#x505A;&#x6570;&#x636E;&#x6D41;&#x8F6C;&#x53D1;&#xFF0C;&#x65E0;&#x6CD5;&#x770B;&#x5230;&#x660E;&#x6587;&#x6570;&#x636E;&#x3002;</li>
<li>&#x6CE8;&#x610F;&#xFF1A;https over http&#x7684;&#x4EE3;&#x7406;&#x6A21;&#x5F0F;&#x4E2D;&#xFF0C;&#x8FD9;&#x91CC;&#x7684;request&#x662F;CONNECT&#x8BF7;&#x6C42;</li>
<li><code>requestDetail</code><ul>
<li><code>host</code> {string} &#x8BF7;&#x6C42;&#x76EE;&#x6807;&#x7684;Host&#xFF0C;&#x53D7;&#x5236;&#x4E8E;&#x534F;&#x8BAE;&#xFF0C;&#x8FD9;&#x91CC;&#x65E0;&#x6CD5;&#x83B7;&#x53D6;&#x5B8C;&#x6574;url</li>
<li><code>_req</code> {object} &#x8BF7;&#x6C42;&#x7684;&#x539F;&#x59CB;request</li>
</ul>
</li>
<li>&#x8FD4;&#x56DE;&#x503C;<ul>
<li><code>true</code>&#x6216;&#x8005;<code>false</code>&#xFF0C;&#x8868;&#x793A;&#x662F;&#x5426;&#x9700;&#x8981;AnyProxy&#x66FF;&#x6362;&#x8BC1;&#x4E66;&#x5E76;&#x89E3;&#x6790;https</li>
</ul>
</li>
</ul>
<h3 id="onerror">onError</h3>
<h4 id="onerrorrequestdetail-error">onError(requestDetail, error)</h4>
<ul>
<li>&#x5728;&#x8BF7;&#x6C42;&#x5904;&#x7406;&#x8FC7;&#x7A0B;&#x4E2D;&#x53D1;&#x751F;&#x9519;&#x8BEF;&#x65F6;&#xFF0C;AnyProxy&#x4F1A;&#x8C03;&#x7528;<code>onError</code>&#x65B9;&#x6CD5;&#xFF0C;&#x5E76;&#x63D0;&#x4F9B;&#x5BF9;&#x5E94;&#x7684;&#x9519;&#x8BEF;&#x4FE1;&#x606F;</li>
<li>&#x591A;&#x6570;&#x573A;&#x666F;&#x4E0B;&#xFF0C;&#x9519;&#x8BEF;&#x4F1A;&#x5728;&#x8BF7;&#x6C42;&#x76EE;&#x6807;&#x670D;&#x52A1;&#x5668;&#x7684;&#x65F6;&#x5019;&#x53D1;&#x751F;&#xFF0C;&#x6BD4;&#x5982;DNS&#x89E3;&#x6790;&#x5931;&#x8D25;&#x3001;&#x8BF7;&#x6C42;&#x8D85;&#x65F6;&#x7B49;</li>
<li><code>requestDetail</code> &#x540C;<code>beforeSendRequest</code>&#x4E2D;&#x7684;&#x53C2;&#x6570;</li>
<li><p>&#x4EE5;&#x4E0B;&#x51E0;&#x79CD;&#x8FD4;&#x56DE;&#x90FD;&#x662F;&#x5408;&#x6CD5;&#x7684;</p>
<ul>
<li>&#x4E0D;&#x505A;&#x4EFB;&#x4F55;&#x5904;&#x7406;&#x3002;&#x6B64;&#x65F6;AnyProxy&#x4F1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x9ED8;&#x8BA4;&#x7684;&#x9519;&#x8BEF;&#x9875;&#x3002;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;
</code></pre>
<ul>
<li>&#x8FD4;&#x56DE;&#x81EA;&#x5B9A;&#x4E49;&#x9519;&#x8BEF;&#x9875;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">return</span> {
  response: {
    statusCode: <span class="hljs-number">200</span>,
    header: { <span class="hljs-string">&apos;content-type&apos;</span>: <span class="hljs-string">&apos;text/html&apos;</span> },
    body: <span class="hljs-string">&apos;this could be a &lt;string&gt; or &lt;buffer&gt;&apos;</span>
  }
};
</code></pre>
</li>
</ul>
<h3 id="onconnecterror">onConnectError</h3>
<h4 id="onconnecterrorrequestdetail-error">onConnectError(requestDetail, error)</h4>
<ul>
<li>AnyProxy&#x5728;&#x4E0E;&#x76EE;&#x6807;HTTPS&#x670D;&#x52A1;&#x5668;&#x5EFA;&#x7ACB;&#x8FDE;&#x63A5;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x5982;&#x679C;&#x53D1;&#x751F;&#x9519;&#x8BEF;&#xFF0C;AnyProxy&#x4F1A;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;</li>
<li><code>requestDetail</code> &#x540C;<code>beforeDealHttpsRequest</code>&#x4E2D;&#x7684;&#x53C2;&#x6570;</li>
<li>&#x6B64;&#x5904;&#x65E0;&#x6CD5;&#x63A7;&#x5236;&#x5411;&#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x8FD4;&#x56DE;&#x4FE1;&#x606F;&#xFF0C;&#x65E0;&#x9700;&#x8FD4;&#x56DE;&#x503C;&#x3002;</li>
</ul>
<h1 id="rule&#x6837;&#x4F8B;">rule&#x6837;&#x4F8B;</h1>
<ul>
<li>&#x8FD9;&#x91CC;&#x63D0;&#x4F9B;&#x4E00;&#x4E9B;&#x6837;&#x4F8B;&#xFF0C;&#x6765;&#x8BB2;&#x89E3;&#x89C4;&#x5219;&#x6A21;&#x5757;&#x7684;&#x5E38;&#x89C1;&#x7528;&#x6CD5;</li>
<li>&#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>anyproxy --rule http://....js</code> &#x6765;&#x52A0;&#x8F7D;&#x6A21;&#x5757;&#x5E76;&#x4F53;&#x9A8C;</li>
<li>&#x7528;curl&#x53D1;&#x8BF7;&#x6C42;&#x6D4B;&#x8BD5;&#x7684;&#x65B9;&#x6CD5;&#x5982;&#x4E0B;<ul>
<li>&#x76F4;&#x63A5;&#x8BF7;&#x6C42;&#x670D;&#x52A1;&#x5668;&#xFF1A;<code>curl http://httpbin.org/</code></li>
<li>&#x901A;&#x8FC7;&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;&#x8BF7;&#x6C42;&#xFF1A;<code>curl http://httpbin.org/ --proxy http://127.0.0.1:8001</code></li>
</ul>
</li>
</ul>
<h3 id="&#x4F7F;&#x7528;&#x672C;&#x5730;&#x6570;&#x636E;">&#x4F7F;&#x7528;&#x672C;&#x5730;&#x6570;&#x636E;</h3>
<ul>
<li>&#x62E6;&#x622A;&#x53D1;&#x9001;&#x5230; <a href="http://httpbin.org" target="_blank">http://httpbin.org</a> &#x7684;&#x8BF7;&#x6C42;&#xFF0C;&#x4F7F;&#x7528;&#x672C;&#x5730;&#x6570;&#x636E;&#x4EE3;&#x66FF;&#x670D;&#x52A1;&#x7AEF;&#x8FD4;&#x56DE;</li>
</ul>
<pre><code class="lang-bash">anyproxy --rule rule_sample/sample_use_<span class="hljs-built_in">local</span>_response.js
</code></pre>
<pre><code class="lang-js"><span class="hljs-comment">/* 
  sample: 
    intercept all requests toward httpbin.org, use a local response
  test:
    curl http://httpbin.org/user-agent --proxy http://127.0.0.1:8001
*/</span>
<span class="hljs-built_in">module</span>.exports = {
  *beforeSendRequest(requestDetail) {
    <span class="hljs-keyword">const</span> localResponse = {
      statusCode: <span class="hljs-number">200</span>,
      header: { <span class="hljs-string">&apos;Content-Type&apos;</span>: <span class="hljs-string">&apos;application/json&apos;</span> },
      body: <span class="hljs-string">&apos;{&quot;hello&quot;: &quot;this is local response&quot;}&apos;</span>
    };
    <span class="hljs-keyword">if</span> (requestDetail.url.indexOf(<span class="hljs-string">&apos;http://httpbin.org&apos;</span>) === <span class="hljs-number">0</span>) {
      <span class="hljs-keyword">return</span> {
        response: localResponse
      };
    }
  },
};
</code></pre>
<h3 id="&#x4FEE;&#x6539;&#x8BF7;&#x6C42;&#x5934;">&#x4FEE;&#x6539;&#x8BF7;&#x6C42;&#x5934;</h3>
<ul>
<li>&#x4FEE;&#x6539;&#x53D1;&#x9001;&#x5230; httpbin.org &#x7684;user-agent</li>
</ul>
<pre><code class="lang-bash">anyproxy --rule rule_sample/sample_modify_request_header.js
</code></pre>
<pre><code class="lang-js"><span class="hljs-comment">/* 
  sample: 
    modify the user-agent in requests toward httpbin.org
  test:
    curl http://httpbin.org/user-agent --proxy http://127.0.0.1:8001
*/</span>
<span class="hljs-built_in">module</span>.exports = {
  *beforeSendRequest(requestDetail) {
    <span class="hljs-keyword">if</span> (requestDetail.url.indexOf(<span class="hljs-string">&apos;http://httpbin.org&apos;</span>) === <span class="hljs-number">0</span>) {
      <span class="hljs-keyword">const</span> newRequestOptions = requestDetail.requestOptions;
      newRequestOptions.headers[<span class="hljs-string">&apos;User-Agent&apos;</span>] = <span class="hljs-string">&apos;AnyProxy/0.0.0&apos;</span>;
      <span class="hljs-keyword">return</span> {
        requestOptions: newRequestOptions
      };
    }
  },
};
</code></pre>
<h3 id="&#x4FEE;&#x6539;&#x8BF7;&#x6C42;&#x6570;&#x636E;">&#x4FEE;&#x6539;&#x8BF7;&#x6C42;&#x6570;&#x636E;</h3>
<ul>
<li>&#x4FEE;&#x6539;&#x53D1;&#x9001;&#x5230; <a href="http://httpbin.org/post" target="_blank">http://httpbin.org/post</a> &#x7684;post&#x6570;&#x636E;</li>
</ul>
<pre><code class="lang-bash">anyproxy --rule rule_sample/sample_modify_request_data.js
</code></pre>
<pre><code class="lang-js"><span class="hljs-comment">/*
  sample:
    modify the post data towards http://httpbin.org/post
  test:
    curl -H &quot;Content-Type: text/plain&quot; -X POST -d &apos;original post data&apos; http://httpbin.org/post --proxy http://127.0.0.1:8001
  expected response:
    { &quot;data&quot;: &quot;i-am-anyproxy-modified-post-data&quot; }
*/</span>
<span class="hljs-built_in">module</span>.exports = {
  summary: <span class="hljs-string">&apos;Rule to modify request data&apos;</span>,
  *beforeSendRequest(requestDetail) {
    <span class="hljs-keyword">if</span> (requestDetail.url.indexOf(<span class="hljs-string">&apos;http://httpbin.org/post&apos;</span>) === <span class="hljs-number">0</span>) {
      <span class="hljs-keyword">return</span> {
        requestData: <span class="hljs-string">&apos;i-am-anyproxy-modified-post-data&apos;</span>
      };
    }
  },
};
</code></pre>
<h3 id="&#x4FEE;&#x6539;&#x8BF7;&#x6C42;&#x7684;&#x76EE;&#x6807;&#x5730;&#x5740;">&#x4FEE;&#x6539;&#x8BF7;&#x6C42;&#x7684;&#x76EE;&#x6807;&#x5730;&#x5740;</h3>
<ul>
<li>&#x628A;&#x6240;&#x6709;&#x53D1;&#x9001;&#x5230; <a href="http://httpbin.org/" target="_blank">http://httpbin.org/</a> &#x7684;&#x8BF7;&#x6C42;&#x5168;&#x90E8;&#x6539;&#x5230; <a href="http://httpbin.org/user-agent" target="_blank">http://httpbin.org/user-agent</a></li>
</ul>
<pre><code class="lang-bash">anyproxy --rule rule_sample/sample_modify_request_path.js
</code></pre>
<pre><code class="lang-js"><span class="hljs-comment">/*
  sample:
    redirect all https://httpbin.org/user-agent requests to http://localhost:8008/index.html
  test:
    curl https://httpbin.org/user-agent --proxy http://127.0.0.1:8001
  expected response:
    &apos;hello world&apos; from 127.0.0.1:8001/index.html
*/</span>
<span class="hljs-built_in">module</span>.exports = {
  *beforeSendRequest(requestDetail) {
    <span class="hljs-keyword">if</span> (requestDetail.url.indexOf(<span class="hljs-string">&apos;https://httpbin.org/user-agent&apos;</span>) === <span class="hljs-number">0</span>) {
      <span class="hljs-keyword">const</span> newRequestOptions = requestDetail.requestOptions;
      requestDetail.protocol = <span class="hljs-string">&apos;http&apos;</span>;
      newRequestOptions.hostname = <span class="hljs-string">&apos;127.0.0.1&apos;</span>
      newRequestOptions.port = <span class="hljs-string">&apos;8008&apos;</span>;
      newRequestOptions.path = <span class="hljs-string">&apos;/index.html&apos;</span>;
      newRequestOptions.method = <span class="hljs-string">&apos;GET&apos;</span>;
      <span class="hljs-keyword">return</span> requestDetail;
    }
  },
  *beforeDealHttpsRequest(requestDetail) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
  }
};
</code></pre>
<h3 id="&#x4FEE;&#x6539;&#x8BF7;&#x6C42;&#x534F;&#x8BAE;">&#x4FEE;&#x6539;&#x8BF7;&#x6C42;&#x534F;&#x8BAE;</h3>
<ul>
<li>&#x628A;&#x7528;http&#x534F;&#x8BAE;&#x8BF7;&#x6C42;&#x7684; <a href="http://httpbin.org" target="_blank">http://httpbin.org</a> &#x6539;&#x6210;https&#x5E76;&#x53D1;&#x9001;</li>
</ul>
<pre><code class="lang-bash">anyproxy --rule rule_sample/sample_modify_request_protocol.js
</code></pre>
<pre><code class="lang-js"><span class="hljs-comment">/* 
  sample: 
    redirect all http requests of httpbin.org to https
  test:
    curl &apos;http://httpbin.org/get?show_env=1&apos; --proxy http://127.0.0.1:8001
  expected response:
    { &quot;X-Forwarded-Protocol&quot;: &quot;https&quot; }
*/</span>
<span class="hljs-built_in">module</span>.exports = {
  *beforeSendRequest(requestDetail) {
    <span class="hljs-keyword">if</span> (requestDetail.url.indexOf(<span class="hljs-string">&apos;http://httpbin.org&apos;</span>) === <span class="hljs-number">0</span>) {
      <span class="hljs-keyword">const</span> newOption = requestDetail.requestOptions;
      newOption.port = <span class="hljs-number">443</span>;
      <span class="hljs-keyword">return</span> {
        protocol: <span class="hljs-string">&apos;https&apos;</span>,
        requestOptions: newOption
      };
    }
  }
};
</code></pre>
<h3 id="&#x4FEE;&#x6539;&#x8FD4;&#x56DE;&#x72B6;&#x6001;&#x7801;">&#x4FEE;&#x6539;&#x8FD4;&#x56DE;&#x72B6;&#x6001;&#x7801;</h3>
<ul>
<li>&#x628A; &#x6240;&#x6709;<a href="http://httpbin.org" target="_blank">http://httpbin.org</a> &#x7684;&#x8FD4;&#x56DE;&#x72B6;&#x6001;&#x7801;&#x90FD;&#x6539;&#x6210;404</li>
</ul>
<pre><code class="lang-bash">anyproxy --rule rule_sample/sample_modify_response_statuscode.js
</code></pre>
<pre><code class="lang-js"><span class="hljs-comment">/* 
  sample: 
    modify all status code of http://httpbin.org/ to 404
  test:
    curl -I &apos;http://httpbin.org/user-agent&apos; --proxy http://127.0.0.1:8001
  expected response:
    HTTP/1.1 404 Not Found
*/</span>
<span class="hljs-built_in">module</span>.exports = {
  *beforeSendResponse(requestDetail, responseDetail) {
    <span class="hljs-keyword">if</span> (requestDetail.url.indexOf(<span class="hljs-string">&apos;http://httpbin.org&apos;</span>) === <span class="hljs-number">0</span>) {
      <span class="hljs-keyword">const</span> newResponse = responseDetail.response;
      newResponse.statusCode = <span class="hljs-number">404</span>;
      <span class="hljs-keyword">return</span> {
        response: newResponse
      };
    }
  }
};
</code></pre>
<h3 id="&#x4FEE;&#x6539;&#x8FD4;&#x56DE;&#x5934;">&#x4FEE;&#x6539;&#x8FD4;&#x56DE;&#x5934;</h3>
<ul>
<li>&#x5728; <a href="http://httpbin.org/user-agent" target="_blank">http://httpbin.org/user-agent</a> &#x7684;&#x8FD4;&#x56DE;&#x5934;&#x91CC;&#x52A0;&#x4E0A; X-Proxy-By:AnyProxy</li>
</ul>
<pre><code class="lang-bash">anyproxy --rule rule_sample/sample_modify_response_header.js
</code></pre>
<pre><code class="lang-js"><span class="hljs-comment">/* 
  sample: 
    modify response header of http://httpbin.org/user-agent
  test:
    curl -I &apos;http://httpbin.org/user-agent&apos; --proxy http://127.0.0.1:8001
  expected response:
    X-Proxy-By: AnyProxy
*/</span>
<span class="hljs-built_in">module</span>.exports = {
  *beforeSendResponse(requestDetail, responseDetail) {
    <span class="hljs-keyword">if</span> (requestDetail.url.indexOf(<span class="hljs-string">&apos;http://httpbin.org/user-agent&apos;</span>) === <span class="hljs-number">0</span>) {
      <span class="hljs-keyword">const</span> newResponse = responseDetail.response;
      newResponse.header[<span class="hljs-string">&apos;X-Proxy-By&apos;</span>] = <span class="hljs-string">&apos;AnyProxy&apos;</span>;
      <span class="hljs-keyword">return</span> {
        response: newResponse
      };
    }
  }
};
</code></pre>
<h3 id="&#x4FEE;&#x6539;&#x8FD4;&#x56DE;&#x5185;&#x5BB9;&#x5E76;&#x5EF6;&#x8FDF;">&#x4FEE;&#x6539;&#x8FD4;&#x56DE;&#x5185;&#x5BB9;&#x5E76;&#x5EF6;&#x8FDF;</h3>
<ul>
<li>&#x5728; <a href="http://httpbin.org/user-agent" target="_blank">http://httpbin.org/user-agent</a> &#x7684;&#x8FD4;&#x56DE;&#x6700;&#x540E;&#x8FFD;&#x52A0;AnyProxy&#x7684;&#x7B7E;&#x540D;&#xFF0C;&#x5E76;&#x5EF6;&#x8FDF;5&#x79D2;</li>
</ul>
<pre><code class="lang-bash">anyproxy --rule rule_sample/sample_modify_response_data.js
</code></pre>
<pre><code class="lang-js"><span class="hljs-comment">/* 
  sample: 
    modify response data of http://httpbin.org/user-agent
  test:
    curl &apos;http://httpbin.org/user-agent&apos; --proxy http://127.0.0.1:8001
  expected response:
    { &quot;user-agent&quot;: &quot;curl/7.43.0&quot; } -- AnyProxy Hacked! --
*/</span>

<span class="hljs-built_in">module</span>.exports = {
  *beforeSendResponse(requestDetail, responseDetail) {
    <span class="hljs-keyword">if</span> (requestDetail.url === <span class="hljs-string">&apos;http://httpbin.org/user-agent&apos;</span>) {
      <span class="hljs-keyword">const</span> newResponse = responseDetail.response;
      newResponse.body += <span class="hljs-string">&apos;-- AnyProxy Hacked! --&apos;</span>;
      <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>((resolve, reject) =&gt; {
        setTimeout(() =&gt; { <span class="hljs-comment">// delay the response for 5s</span>
          resolve({ response: newResponse });
        }, <span class="hljs-number">5000</span>);
      });
    }
  },
};
</code></pre>
<h1 id="&#x8BC1;&#x4E66;&#x914D;&#x7F6E;">&#x8BC1;&#x4E66;&#x914D;&#x7F6E;</h1>
<h3 id="osx&#x7CFB;&#x7EDF;&#x4FE1;&#x4EFB;ca&#x8BC1;&#x4E66;">OSX&#x7CFB;&#x7EDF;&#x4FE1;&#x4EFB;CA&#x8BC1;&#x4E66;</h3>
<ul>
<li>&#x7C7B;&#x4F3C;&#x8FD9;&#x79CD;&#x62A5;&#x9519;&#x90FD;&#x662F;&#x56E0;&#x4E3A;&#x7CFB;&#x7EDF;&#x6CA1;&#x6709;&#x4FE1;&#x4EFB;AnyProxy&#x751F;&#x6210;&#x7684;CA&#x6240;&#x9020;&#x6210;&#x7684;</li>
</ul>
<p><img src="https://zos.alipayobjects.com/rmsportal/CBkLGYgvoHAYwNVAYkpk.png" width="450"></p>
<blockquote>
<p>&#x8B66;&#x544A;&#xFF1A;CA&#x8BC1;&#x4E66;&#x548C;&#x7CFB;&#x7EDF;&#x5B89;&#x5168;&#x606F;&#x606F;&#x76F8;&#x5173;&#xFF0C;&#x5EFA;&#x8BAE;&#x4EB2;&#x81EA;&#x751F;&#x6210;&#xFF0C;&#x5E76;&#x59A5;&#x5584;&#x4FDD;&#x7BA1;</p>
</blockquote>
<p>&#x5B89;&#x88C5;CA&#xFF1A;</p>
<ul>
<li><p>&#x53CC;&#x51FB;&#x6253;&#x5F00;<em>rootCA.crt</em></p>
</li>
<li><p>&#x786E;&#x8BA4;&#x5C06;&#x8BC1;&#x4E66;&#x6DFB;&#x52A0;&#x5230;login&#x6216;system</p>
</li>
</ul>
<p><img src="https://zos.alipayobjects.com/rmsportal/bCwNUFFpvsmVuljQKrIk.png" width="350"></p>
<ul>
<li>&#x627E;&#x5230;&#x521A;&#x521A;&#x5BFC;&#x5165;&#x7684;AnyProxy&#x8BC1;&#x4E66;&#xFF0C;&#x914D;&#x7F6E;&#x4E3A;&#x4FE1;&#x4EFB;&#xFF08;Always Trust&#xFF09;</li>
</ul>
<p><img src="https://zos.alipayobjects.com/rmsportal/HOmEElNGdoZEWFMLsTNT.png" width="700"></p>
<h3 id="windows&#x7CFB;&#x7EDF;&#x4FE1;&#x4EFB;ca&#x8BC1;&#x4E66;">Windows&#x7CFB;&#x7EDF;&#x4FE1;&#x4EFB;CA&#x8BC1;&#x4E66;</h3>
<p><img src="https://t.alipayobjects.com/tfscom/T1D3hfXeFtXXXXXXXX.jpg" width="700"></p>
<h3 id="&#x914D;&#x7F6E;osx&#x7CFB;&#x7EDF;&#x4EE3;&#x7406;">&#x914D;&#x7F6E;OSX&#x7CFB;&#x7EDF;&#x4EE3;&#x7406;</h3>
<ul>
<li>&#x5728;wifi&#x9AD8;&#x7EA7;&#x8BBE;&#x7F6E;&#x4E2D;&#xFF0C;&#x914D;&#x7F6E;http&#x4EE3;&#x7406;&#x5373;&#x53EF;</li>
</ul>
<p><img src="https://zos.alipayobjects.com/rmsportal/vduwhobSTypTfgniBvoa.png" width="500"></p>
<h3 id="&#x914D;&#x7F6E;&#x6D4F;&#x89C8;&#x5668;http&#x4EE3;&#x7406;">&#x914D;&#x7F6E;&#x6D4F;&#x89C8;&#x5668;HTTP&#x4EE3;&#x7406;</h3>
<ul>
<li>&#x4EE5;Chrome&#x7684;<a href="https://chrome.google.com/webstore/detail/padekgcemlokbadohgkifijomclgjgif" target="_blank">SwitchyOmega&#x63D2;&#x4EF6;</a>&#x4E3A;&#x4F8B;</li>
</ul>
<p><img src="https://zos.alipayobjects.com/rmsportal/jIPZrKmqXRaSledQeJUJ.png" width="500"></p>
<h3 id="ios&#x7CFB;&#x7EDF;&#x4FE1;&#x4EFB;ca&#x8BC1;&#x4E66;">iOS&#x7CFB;&#x7EDF;&#x4FE1;&#x4EFB;CA&#x8BC1;&#x4E66;</h3>
<ul>
<li>&#x70B9;&#x51FB;web ui&#x4E2D;&#x7684; <em>Root CA</em>&#xFF0C;&#x6309;&#x63D0;&#x793A;&#x626B;&#x63CF;&#x4E8C;&#x7EF4;&#x7801;&#x5373;&#x53EF;&#x5B89;&#x88C5;</li>
</ul>
<p><img src="https://zos.alipayobjects.com/rmsportal/BrugmMelGVysLDOIBblj.png" width="260"></p>
<h3 id="ios--103&#x4FE1;&#x4EFB;ca&#x8BC1;&#x4E66;">iOS &gt;= 10.3&#x4FE1;&#x4EFB;CA&#x8BC1;&#x4E66;</h3>
<ul>
<li>&#x9664;&#x4E86;&#x4E0A;&#x8FF0;&#x8BC1;&#x4E66;&#x5B89;&#x88C5;&#x8FC7;&#x7A0B;&#xFF0C;&#x8FD8;&#x9700;&#x8981;&#x5728; <em>&#x8BBE;&#x7F6E;-&gt;&#x901A;&#x7528;-&gt;&#x5173;&#x4E8E;&#x672C;&#x673A;-&gt;&#x8BC1;&#x4E66;&#x4FE1;&#x4EFB;&#x8BBE;&#x7F6E;</em> &#x4E2D;&#x628A;AnyProxy&#x8BC1;&#x4E66;&#x7684;&#x5F00;&#x5173;&#x6253;&#x5F00;&#xFF0C;&#x5426;&#x5219;safari&#x5C06;&#x62A5;&#x9519;&#x3002;</li>
</ul>
<p><img src="https://zos.alipayobjects.com/rmsportal/hVWkXHrzHmOKOtCKGUWx.png" width="500"></p>
<h3 id="&#x5B89;&#x5353;&#x7CFB;&#x7EDF;&#x4FE1;&#x4EFB;ca&#x8BC1;&#x4E66;">&#x5B89;&#x5353;&#x7CFB;&#x7EDF;&#x4FE1;&#x4EFB;CA&#x8BC1;&#x4E66;</h3>
<p>&#x9996;&#x5148;&#x548C;iOS&#x7C7B;&#x4F3C;&#xFF0C;&#x9700;&#x8981;&#x5148;&#x626B;&#x63CF;&#x8BC1;&#x4E66;&#x7684;&#x4E8C;&#x7EF4;&#x7801;&#x8FDB;&#x884C;&#x4E0B;&#x8F7D;&#x3002;&#x7136;&#x540E;&#x4E0D;&#x540C;&#x7684;&#x5B89;&#x5353;&#x7CFB;&#x7EDF;&#x5B89;&#x88C5;&#x8BC1;&#x4E66;&#x7684;&#x65B9;&#x5F0F;&#x53EF;&#x80FD;&#x6709;&#x6240;&#x4E0D;&#x540C;&#xFF0C;&#x4F46;&#x662F;&#x5B89;&#x88C5;&#x7684;&#x6B65;&#x9AA4;&#x662F;&#x7C7B;&#x4F3C;&#x7684;&#xFF0C;&#x6211;&#x4EEC;&#x5217;&#x4E3E;&#x4E86;&#x51E0;&#x79CD;&#x7C7B;&#x578B;&#x3002;</p>
<ul>
<li>&#x4E0B;&#x8F7D;&#x540E;&#x7684;&#x8BC1;&#x4E66;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x5355;&#x51FB;&#x6253;&#x5F00;&#x5E76;&#x5B89;&#x88C5;&#xFF0C;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x662F;&#x6700;&#x7B80;&#x5355;&#x7684;&#xFF0C;&#x76F4;&#x63A5;&#x5B89;&#x88C5;&#x5373;&#x53EF;</li>
<li>&#x8BC1;&#x4E66;&#x4E0B;&#x8F7D;&#x5230;&#x6307;&#x5B9A;&#x76EE;&#x5F55;&#x540E;&#xFF0C;&#x9700;&#x8981;&#x4ECE;&#x5176;&#x4ED6;&#x5165;&#x53E3;&#x8FDB;&#x884C;&#x5B89;&#x88C5;&#xFF0C;&#x5305;&#x62EC;&#xFF1A;<ul>
<li>&#x8BBE;&#x7F6E; -&gt; &#x5B89;&#x5168;&#x6027;&#x4E0E;&#x4F4D;&#x7F6E;&#x4FE1;&#x606F; -&gt; &#x52A0;&#x5BC6;&#x4E0E;&#x51ED;&#x636E; -&gt; &#x4ECE;&#x5B58;&#x50A8;&#x8BBE;&#x5907;&#x5B89;&#x88C5;&#x3002;&#x627E;&#x5230;&#x4F60;&#x4E0B;&#x8F7D;&#x7684;&#x8BC1;&#x4E66;&#x6587;&#x4EF6;&#xFF0C;&#x8FDB;&#x884C;&#x5B89;&#x88C5;</li>
<li>&#x8BBE;&#x7F6E; -&gt; &#x5B89;&#x5168; -&gt; &#x4ECE;SD&#x5361;&#x5B89;&#x88C5;&#x8BC1;&#x4E66;&#x3002;&#x627E;&#x5230;&#x4F60;&#x4E0B;&#x8F7D;&#x7684;&#x8BC1;&#x4E66;&#x6587;&#x4EF6;&#xFF0C;&#x8FDB;&#x884C;&#x5B89;&#x88C5;</li>
</ul>
</li>
</ul>
<p>&#x4E0D;&#x540C;&#x5B89;&#x5353;&#x7CFB;&#x7EDF;&#x652F;&#x6301;&#x5B89;&#x88C5;&#x7684;&#x8BC1;&#x4E66;&#x6587;&#x4EF6;&#x7C7B;&#x578B;&#x4E0D;&#x5C3D;&#x76F8;&#x540C;&#xFF0C;&#x5927;&#x591A;&#x652F;&#x6301;&#x5B89;&#x88C5;&#x62D3;&#x5C55;&#x540D;&#x4E3A; .crt &#x7684;&#x8BC1;&#x4E66;&#x6587;&#x4EF6;&#xFF0C;&#x5C11;&#x90E8;&#x5206;&#x4EC5;&#x652F;&#x6301; .cer &#x6587;&#x4EF6;&#xFF08;&#x5DF2;&#x77E5;&#x5982; OPPO R15&#xFF09;&#xFF0C;AnyProxy &#x63D0;&#x4F9B;&#x4E86;&#x591A;&#x79CD;&#x7C7B;&#x578B;&#x7684;&#x8BC1;&#x4E66;&#x6587;&#x4EF6;&#xFF0C;&#x53EF;&#x5728;&#x4E0B;&#x8F7D;&#x5B89;&#x88C5;&#x65F6;&#x9009;&#x62E9;&#x3002;</p>
<h3 id="&#x914D;&#x7F6E;iosandroid&#x7CFB;&#x7EDF;&#x4EE3;&#x7406;">&#x914D;&#x7F6E;iOS/Android&#x7CFB;&#x7EDF;&#x4EE3;&#x7406;</h3>
<ul>
<li><p>&#x4EE3;&#x7406;&#x670D;&#x52A1;&#x5668;&#x90FD;&#x5728;wifi&#x8BBE;&#x7F6E;&#x4E2D;&#x914D;&#x7F6E;</p>
</li>
<li><p>iOS HTTP&#x4EE3;&#x7406;&#x914D;&#x7F6E;</p>
</li>
</ul>
<p><img src="https://zos.alipayobjects.com/rmsportal/tLGqIozhffTccUgPakuw.png" width="260"></p>
<ul>
<li>Android HTTP&#x4EE3;&#x7406;&#x914D;&#x7F6E;</li>
</ul>
<p><img src="https://zos.alipayobjects.com/rmsportal/YQtbQYVNuOszZGdAOauU.png" width="260"></p>
<h1 id="faq">FAQ</h1>
<h4 id="q-&#x4E3A;&#x4EC0;&#x4E48;https&#x8BF7;&#x6C42;&#x4E0D;&#x80FD;&#x8FDB;&#x5165;&#x5904;&#x7406;&#x51FD;&#x6570;&#xFF1F;">Q: &#x4E3A;&#x4EC0;&#x4E48;https&#x8BF7;&#x6C42;&#x4E0D;&#x80FD;&#x8FDB;&#x5165;&#x5904;&#x7406;&#x51FD;&#x6570;&#xFF1F;</h4>
<p> A: &#x4EE5;&#x4E0B;&#x4EFB;&#x610F;&#x4E00;&#x9879;&#x90FD;&#x80FD;&#x7528;&#x6765;&#x6539;&#x53D8;https&#x7684;&#x5904;&#x7406;&#x7279;&#x6027;&#xFF1A;</p>
<pre><code> 1. &#x547D;&#x4EE4;&#x884C;&#x542F;&#x52A8;AnyProxy&#x65F6;&#x914D;&#x7F6E;`--intercept`&#x53C2;&#x6570;&#xFF0C;&#x6309;npm&#x6A21;&#x5757;&#x542F;&#x52A8;&#x65F6;&#x914D;&#x7F6E;`forceProxyHttps`&#x53C2;&#x6570;&#xFF0C;&#x6240;&#x6709;Https&#x8BF7;&#x6C42;&#x90FD;&#x4F1A;&#x88AB;&#x66FF;&#x6362;&#x8BC1;&#x4E66;&#x5E76;&#x89E3;&#x6790;
 2. &#x89C4;&#x5219;&#x6587;&#x4EF6;&#x5185;&#x63D0;&#x4F9B;`beforeDealHttpsRequest`&#x65B9;&#x6CD5;&#xFF0C;&#x8FD4;&#x56DE; *true* &#x7684;https&#x8BF7;&#x6C42;&#x4F1A;&#x88AB;&#x89E3;&#x6790;
</code></pre><h4 id="q-&#x63D0;&#x793A;-function-is-not-yieldable">Q: &#x63D0;&#x793A; <em>function is not yieldable</em></h4>
<ul>
<li>A: &#x89C4;&#x5219;&#x6A21;&#x5757;&#x662F;&#x7528; <a href="https://www.npmjs.com/package/co" target="_blank">co</a> &#x9A71;&#x52A8;&#x7684;&#xFF0C;&#x51FD;&#x6570;&#x9700;&#x8981;&#x6EE1;&#x8DB3;yieldable&#x3002;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;generator&#x65B9;&#x6CD5;&#x6216;&#x662F;&#x8FD4;&#x56DE;Promise&#x3002;</li>
</ul>
<h4 id="q-the-connection-is-not-private">Q: The connection is not private</h4>
<p>&#x5F53;&#x8BBF;&#x95EE;&#x7279;&#x5B9A;&#x7684;HTTPS&#x7AD9;&#x70B9;&#xFF0C;AnyProxy&#x4F1A;&#x63D0;&#x793A;&#x8BE5;&#x7AD9;&#x70B9;&#x4E0D;&#x662F;&#x4E00;&#x4E2A;&#x5B89;&#x5168;&#x7684;&#x7F51;&#x7AD9;&#xFF0C;&#x8FD9;&#x901A;&#x5E38;&#x662F;&#x56E0;&#x4E3A;&#x7AD9;&#x70B9;&#x7684;&#x8BC1;&#x4E66;&#x8BBE;&#x7F6E;&#x4E0D;&#x80FD;&#x88AB;&#x6B63;&#x786E;&#x8BC6;&#x522B;&#x5BFC;&#x81F4;&#x7684;&#xFF08;&#x6BD4;&#x5982;&#xFF0C;&#x7AD9;&#x70B9;&#x7684;&#x8BC1;&#x4E66;&#x662F;&#x81EA;&#x7B7E;&#x53D1;&#x7684;&#xFF09;&#x3002;&#x5982;&#x679C;&#x60A8;&#x4FE1;&#x4EFB;&#x8BE5;&#x7F51;&#x7AD9;&#xFF0C;&#x53EF;&#x4EE5;&#x7528;&#x4EE5;&#x4E0B;&#x65B9;&#x5F0F;&#x6765;&#x7EE7;&#x7EED;&#x8BBF;&#x95EE;&#xFF1A;</p>
<ul>
<li><p>&#x547D;&#x4EE4;&#x884C;&#x76F4;&#x63A5;&#x542F;&#x52A8;</p>
<p>&#x901A;&#x8FC7;&#x542F;&#x52A8;&#x53C2;&#x6570; <code>--ignore-unauthorized-ssl</code> &#x6765;&#x5FFD;&#x7565;&#x8BC1;&#x4E66;&#x8BA4;&#x8BC1;&#x7684;&#x9519;&#x8BEF;&#x3002;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x8BE5;&#x53C2;&#x6570;&#x662F;&#x5168;&#x5C40;&#x751F;&#x6548;&#x7684;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x5728;&#x6B64;&#x671F;&#x95F4;&#x8BBF;&#x95EE;&#x4E86;&#x5176;&#x4ED6;&#x672A;&#x77E5;&#x7684;&#x7F51;&#x7AD9;&#xFF0C;&#x4ED6;&#x4EEC;&#x7684;&#x8BC1;&#x4E66;&#x95EE;&#x9898;&#x4E5F;&#x4F1A;&#x88AB;&#x5FFD;&#x7565;&#xFF0C;&#x8FD9;&#x53EF;&#x80FD;&#x4F1A;&#x5E26;&#x6765;&#x5B89;&#x5168;&#x9690;&#x60A3;&#x3002;</p>
<pre><code class="lang-bash">anyproxy -i --ignore-unauthorized-ssl
</code></pre>
</li>
<li><p>&#x5728;Nodejs&#x4EE3;&#x7801;&#x4E2D;&#x542F;&#x52A8;</p>
<p>&#x5728;&#x6784;&#x9020;AnyProxy&#x5B9E;&#x4F8B;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F20;&#x5165;&#x53C2;&#x6570;<code>dangerouslyIgnoreUnauthorized:true</code>, &#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"> <span class="hljs-keyword">const</span> options = {
  ...,
  dangerouslyIgnoreUnauthorized: <span class="hljs-literal">true</span>
 };

 <span class="hljs-keyword">const</span> anyproxyIns = <span class="hljs-keyword">new</span> AnyProxy.ProxyCore(options);
 anyproxyIns.start();
</code></pre>
<p><em>&#x901A;&#x8FC7;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x521D;&#x59CB;&#x5316;&#x7684;AnyProxy&#xFF0C;&#x5176;&#x914D;&#x7F6E;&#x4E5F;&#x662F;&#x5168;&#x5C40;&#x6027;&#x7684;&#xFF0C;&#x6240;&#x6709;&#x7F51;&#x7AD9;&#x7684;&#x8BC1;&#x4E66;&#x95EE;&#x9898;&#x90FD;&#x4F1A;&#x88AB;&#x5FFD;&#x7565;</em></p>
</li>
<li><p>&#x901A;&#x8FC7;&#x81EA;&#x5B9A;&#x4E49;&#x7684;Rule&#x6765;&#x4FEE;&#x6539;</p>
<p>&#x6211;&#x4EEC;&#x81EA;&#x7136;&#x4E5F;&#x53EF;&#x4EE5;&#x501F;&#x52A9;&#x81EA;&#x5B9A;&#x4E49;&#x7684;Rule&#x6765;&#x5B9E;&#x73B0;&#x8FD9;&#x4E2A;&#x6548;&#x679C;&#xFF0C;&#x800C;&#x4E14;&#x6211;&#x4EEC;&#x8FD8;&#x53EF;&#x4EE5;&#x63A7;&#x5236;&#x5230;&#x53EA;&#x5141;&#x8BB8;&#x6307;&#x5B9A;&#x7F51;&#x5740;&#x7684;&#x8BC1;&#x4E66;&#x9519;&#x8BEF;&#xFF0C;&#x5BF9;&#x4E0D;&#x5728;&#x5217;&#x8868;&#x7684;&#x7F51;&#x5740;&#xFF0C;&#x8FDB;&#x884C;&#x8BC1;&#x4E66;&#x7684;&#x5F3A;&#x9A8C;&#x8BC1;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-built_in">module</span>.exports = {
  *beforeSendRequest(requestDetail) {
    <span class="hljs-keyword">if</span> (requestDetail.url.indexOf(<span class="hljs-string">&apos;https://the-site-you-know.com&apos;</span>) === <span class="hljs-number">0</span>) {
      <span class="hljs-keyword">const</span> newRequestOptions = requestDetail.requestOptions;
      <span class="hljs-comment">// &#x8BBE;&#x7F6E;&#x5C5E;&#x6027; rejectUnauthorized &#x4E3A; false</span>
      newRequestOptions.rejectUnauthorized = <span class="hljs-literal">false</span>;
      <span class="hljs-keyword">return</span> {
        requestOptions: newRequestOptions
      };
    }
  },
};
</code></pre>
</li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                
                <a href="./#快速开始" class="navigation navigation-next navigation-unique" aria-label="Next page: 快速开始">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"简介","level":"1.1","depth":1,"next":{"title":"快速开始","level":"1.2","depth":1,"anchor":"#快速开始","path":"README.md","ref":"README.md#快速开始","articles":[{"title":"安装","level":"1.2.1","depth":2,"anchor":"#安装","path":"README.md","ref":"README.md#安装","articles":[]},{"title":"启动","level":"1.2.2","depth":2,"anchor":"#启动","path":"README.md","ref":"README.md#启动","articles":[]},{"title":"其他命令","level":"1.2.3","depth":2,"anchor":"#其他命令","path":"README.md","ref":"README.md#其他命令","articles":[]},{"title":"作为npm模块启动","level":"1.2.4","depth":2,"anchor":"#作为npm模块使用","path":"README.md","ref":"README.md#作为npm模块使用","articles":[]}]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"AnyProxy","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"AnyProxy","language":"cn","gitbook":"*","description":"A fully configurable http/https proxy in NodeJS"},"file":{"path":"README.md","mtime":"2019-03-26T12:49:35.827Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2019-03-26T12:49:36.852Z"},"basePath":".","book":{"language":"cn"}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

